// 自定义表单验证规则
const validateStrengthMax = (rule, value, callback, NewForm) => {
  if (NewForm.strengthmax < NewForm.strengthmin) {
    callback(new Error("光照强度上限不能低于下限"));
  } else {
    callback();
  }
};

const validateStrengthMin = (rule, value, callback, NewForm) => {
  if (NewForm.strengthmin > NewForm.strengthmax) {
    callback(new Error("光照强度下限不能高于上限"));
  } else {
    callback();
  }
};

const validateTemperatureMax = (rule, value, callback, NewForm) => {
  if (NewForm.temperaturemax < NewForm.temperaturemin) {
    callback(new Error("温度上限不能低于下限"));
  } else {
    callback();
  }
};

const validateTemperatureMin = (rule, value, callback, NewForm) => {
  if (NewForm.temperaturemin > NewForm.temperaturemax) {
    callback(new Error("温度下限不能高于上限"));
  } else {
    callback();
  }
};

// 表单验证规则
const FormRules = (NewForm) => ({
  temperaturemax: [
    { required: true, message: "请输入温度上限", trigger: "blur" },
    { validator: (rule, value, callback) => validateTemperatureMax(rule, value, callback, NewForm), trigger: "blur" },
  ],
  temperaturemin: [
    { required: true, message: "请输入温度下限", trigger: "blur" },
    { validator: (rule, value, callback) => validateTemperatureMin(rule, value, callback, NewForm), trigger: "blur" },
  ],
  strengthmax: [
    { required: true, message: "请输入光照强度上限", trigger: "blur" },
    { validator: (rule, value, callback) => validateStrengthMax(rule, value, callback, NewForm), trigger: "blur" },
  ],
  strengthmin: [
    { required: true, message: "请输入光照强度下限", trigger: "blur" },
    { validator: (rule, value, callback) => validateStrengthMin(rule, value, callback, NewForm), trigger: "blur" },
  ],
  did: [{ required: true, message: "请输入设备ID", trigger: "blur" }],
  starttime: [{ required: true, message: "请选择开始时间", trigger: "blur" }],
  endtime: [{ required: true, message: "请选择结束时间", trigger: "blur" }],
});

export default FormRules;
